package com.briup.shopadmin.service.impl;

import com.briup.shopadmin.common.GlobalException;
import com.briup.shopadmin.common.bean.Order;
import com.briup.shopadmin.dao.IOrderDao;
import com.briup.shopadmin.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class OrderServiceImpl implements IOrderService {
    @Autowired
    IOrderDao orderDao;
    @Override
    public Page<Order> getOrderInfo(String orderId, String status, Integer pageSize, Integer pageNum) {
        if (pageNum<1||pageNum<1){
            throw new GlobalException(52001,"分页参数异常");
        }
        PageRequest request = PageRequest.of(pageNum - 1, pageSize);
        Page<Order> page = orderDao.findByIdContainingAndStatusContaining(orderId, status, request);

        return page;
    }

    @Override
    public void update(Order order) {
        orderDao.save(order);
    }

    @Override
    public Order getOrder(String id) {
        Optional<Order> optional = orderDao.findById(id);
        return optional.get();
    }
}
